local manjia = fk.CreateSkill{
  name = "swis__manjia",
}

Fk:loadTranslationTable{
  ["swis__manjia"] = "蛮甲",
  [":swis__manjia"] = "当一名角色需要发动〖藤甲〗时，你可以弃置一张牌并令其发动之。若有牌因此对其无效，你摸三张牌。若为你需要发动，你须如此做。",

  ["#swis__manjia-discard"] = "蛮甲：你可以弃置一张牌并令%src发动〖藤甲〗",

  ["$swis__manjia1"] = "藤甲军从无对手，不服来战！",
  ["$swis__manjia2"] = "尔等，竟如此歹毒！",
}

manjia:addEffect(fk.PreCardEffect, {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(manjia.name) then
      return table.contains({"slash", "savage_assault", "archery_attack"}, data.card.name)
      and not table.find(data.to:getCardIds("e"), function (c)
        return Fk:getCardById(c).name == "vine"
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cardIds = room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      skill_name = manjia.name,
      cancelable = (player ~= data.to),
      prompt = "#swis__manjia-discard:"..data.to.id,
      skip = true,
      include_equip = true,
    })
    if #cardIds > 0 then
      event:setCostData(self, cardIds)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(manjia.name, 1)
    room:notifySkillInvoked(player, manjia.name, "defensive")
    room:sendLog{
      type = "#InvokeSkill",
      from = data.to.id,
      arg = "vine",
    }
    room:broadcastPlaySound("./packages/maneuvering/audio/card/vine")
    room:setEmotion(data.to, "./packages/maneuvering/image/anim/vine")
    room:throwCard(event:getCostData(self), manjia.name, player, player)
    player:drawCards(3, manjia.name)
    data.nullified = true
  end,
})

manjia:addEffect(fk.DamageInflicted, {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(manjia.name) then
      return data.damageType == fk.FireDamage
      and not table.find(target:getCardIds("e"), function (c)
        return Fk:getCardById(c).name == "vine"
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cardIds = room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      skill_name = manjia.name,
      cancelable = (player ~= data.to),
      prompt = "#swis__manjia-discard:"..data.to.id,
      skip = true,
      include_equip = true,
    })
    if #cardIds > 0 then
      event:setCostData(self, cardIds)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(manjia.name, 2)
    room:notifySkillInvoked(player, manjia.name, "negative")
    room:sendLog{
      type = "#InvokeSkill",
      from = data.to.id,
      arg = "vine",
    }
    room:broadcastPlaySound("./packages/maneuvering/audio/card/vineburn")
    room:setEmotion(target, "./packages/maneuvering/image/anim/vineburn")
    room:throwCard(event:getCostData(self), manjia.name, player, player)
    data:changeDamage(1)
  end
})

return manjia